package java_demos.java_io.create_file;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class CreateFileJava8 {
    public static void main(String[] args) {
        // create a file named "create_file_java8.txt" in the current directory.
        String fileName = "create_file_java8.txt";

        Path path = Paths.get(fileName);

        // default, create, truncate and write to it.
        try (BufferedWriter writer =
                     Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {

            writer.write("Hello World !!");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
